package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.MallBanner;
import com.sc.nft.entity.vo.MallBannerVO;
import com.sc.nft.mapper.MallBannerMapper;
import com.sc.nft.sup.PageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 商城banner表(MallBanner)表Dao层
 *
 * @author wwc
 * @since 2023-05-16 10:58:41
 */
@Slf4j
@Repository
public class MallBannerDao extends ServiceImpl<MallBannerMapper, MallBanner> {

    /**
     * 根据id获取数据
     *
     * @param id
     * @param status
     * @return
     */
    public MallBanner getByIdAndStatus(Long id, Integer status) {
        LambdaQueryWrapper<MallBanner> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MallBanner::getId, id);
        lambdaQueryWrapper.eq(status != null, MallBanner::getStatus, status);
        lambdaQueryWrapper.eq(MallBanner::getLocation,Boolean.FALSE);
        return baseMapper.selectOne(lambdaQueryWrapper);
    }

    public List<MallBanner>listByLocationAndStatus(Long location,Integer status){
        LambdaQueryWrapper<MallBanner> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(status != null, MallBanner::getStatus, status);
        lambdaQueryWrapper.eq(location != null, MallBanner::getLocation, location);
        lambdaQueryWrapper.eq(MallBanner::getLocation,Boolean.FALSE);
        lambdaQueryWrapper.orderByDesc(MallBanner::getSort);
        return baseMapper.selectList(lambdaQueryWrapper);
    }
    public List<MallBannerVO>listByLocationAndStatusAndTime(Long location, Integer status, Date date){
        return baseMapper.listByLocationAndStatusAndTime(location, status , date);
    }

    public Page<MallBannerVO> pageAdmin(PageRequest request){
        return baseMapper.pageAdmin(request.toMp());
    }

}
